package com.cskaoyan.service;

import com.cskaoyan.bean.System;
import com.cskaoyan.bean.SystemExample;
import com.cskaoyan.bean.WxConfig;
import com.cskaoyan.bean.dto.ExpressConfigDto;
import com.cskaoyan.bean.dto.MallConfigDto;
import com.cskaoyan.bean.dto.OrderConfigDto;
import com.cskaoyan.mapper.SystemMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminConfigServiceImpl implements AdminConfigService {
    @Autowired
    SystemMapper systemMapper;

    @Override
    public MallConfigDto selectMallConfig() {
        MallConfigDto mallConfig = systemMapper.selectMallConfig();
        return mallConfig;
    }

    @Override
    public int updateMallConfig(MallConfigDto mallConfig) {
        SystemExample systemExample1 = new SystemExample();
        systemExample1.createCriteria().andKeyNameEqualTo("cskaoyan_mall_mallName");
        SystemExample systemExample2 = new SystemExample();
        systemExample2.createCriteria().andKeyNameEqualTo("cskaoyan_mallMallPhone");
        SystemExample systemExample3 = new SystemExample();
        systemExample3.createCriteria().andKeyNameEqualTo("cskaoyan_mall_mall_qq");
        SystemExample systemExample4 = new SystemExample();
        systemExample4.createCriteria().andKeyNameEqualTo("cskaoyan_mall_mall_address");
        System system1 = new System();
        system1.setKeyValue(mallConfig.getCskaoyanmall_mall_name());
        System system2 = new System();
        system2.setKeyValue(mallConfig.getCskaoyanmall_mall_phone());
        System system3 = new System();
        system3.setKeyValue(mallConfig.getCskaoyanmall_mall_qq());
        System system4 = new System();
        system4.setKeyValue(mallConfig.getCskaoyanmall_mall_address());
        systemMapper.updateByExampleSelective(system1, systemExample1);
        systemMapper.updateByExampleSelective(system2, systemExample2);
        systemMapper.updateByExampleSelective(system3, systemExample3);
        systemMapper.updateByExampleSelective(system4, systemExample4);
        return 200;
    }

    @Override
    public ExpressConfigDto selectExpressConfig() {
        ExpressConfigDto expressConfig = systemMapper.selectExpressConfig();
        return expressConfig;
    }

    @Override
    public void updateExpressConfig(ExpressConfigDto expressConfig) {
        SystemExample systemExample1 = new SystemExample();
        systemExample1.createCriteria().andKeyNameEqualTo("cskaoyan_mall_express_freight_value");
        SystemExample systemExample2 = new SystemExample();
        systemExample2.createCriteria().andKeyNameEqualTo("cskaoyan_mall_express_freight_min");
        System system1 = new System();
        system1.setKeyValue(expressConfig.getCskaoyanmall_express_freight_value());
        System system2 = new System();
        system2.setKeyValue(expressConfig.getCskaoyanmall_express_freight_min());
        systemMapper.updateByExampleSelective(system1, systemExample1);
        systemMapper.updateByExampleSelective(system2, systemExample2);
    }

    @Override
    public OrderConfigDto selectOrderConfig() {
        OrderConfigDto orderConfigDto = systemMapper.selectOrderConfig();
        return orderConfigDto;
    }

    @Override
    public void updateOrderConfig(OrderConfigDto orderConfig) {
        SystemExample systemExample1 = new SystemExample();
        systemExample1.createCriteria().andKeyNameEqualTo("cskaoyan_mall_order_unconfirm");
        SystemExample systemExample2 = new SystemExample();
        systemExample2.createCriteria().andKeyNameEqualTo("cskaoyan_mall_order_unpaid");
        SystemExample systemExample3 = new SystemExample();
        systemExample3.createCriteria().andKeyNameEqualTo("cskaoyan_mall_order_comment");
        System system1 = new System();
        system1.setKeyValue(orderConfig.getCskaoyanmall_order_unconfirm());
        System system2 = new System();
        system2.setKeyValue(orderConfig.getCskaoyanmall_order_unpaid());
        System system3 = new System();
        system3.setKeyValue(orderConfig.getCskaoyanmall_order_comment());
        systemMapper.updateByExampleSelective(system1, systemExample1);
        systemMapper.updateByExampleSelective(system2, systemExample2);
        systemMapper.updateByExampleSelective(system3, systemExample3);
    }

    @Override
    public WxConfig selectWxConfig() {
        WxConfig wxConfig = systemMapper.selectWxConfig();
        return wxConfig;
    }

    @Override
    public void updateWxConfig(WxConfig wxConfig) {
        SystemExample systemExample1 = new SystemExample();
        systemExample1.createCriteria().andKeyNameEqualTo("cskaoyan_mall_wx_share");
        SystemExample systemExample2 = new SystemExample();
        systemExample2.createCriteria().andKeyNameEqualTo("cskaoyan_mall_wx_index_brand");
        SystemExample systemExample3 = new SystemExample();
        systemExample3.createCriteria().andKeyNameEqualTo("cskaoyan_mall_wx_index_topic");
        SystemExample systemExample4 = new SystemExample();
        systemExample4.createCriteria().andKeyNameEqualTo("cskaoyan_mall_wx_index_hot");
        SystemExample systemExample5 = new SystemExample();
        systemExample5.createCriteria().andKeyNameEqualTo("cskaoyan_mall_wx_catlog_goods");
        SystemExample systemExample6 = new SystemExample();
        systemExample6.createCriteria().andKeyNameEqualTo("cskaoyan_mall_wx_catlog_list");
        SystemExample systemExample7 = new SystemExample();
        systemExample7.createCriteria().andKeyNameEqualTo("cskaoyan_mall_wx_index_new");
        System system1 = new System();
        system1.setKeyValue(wxConfig.getCskaoyanmall_wx_share());
        System system2 = new System();
        system2.setKeyValue(wxConfig.getCskaoyanmall_wx_index_brand());
        System system3 = new System();
        system3.setKeyValue(wxConfig.getCskaoyanmall_wx_index_topic());
        System system4 = new System();
        system4.setKeyValue(wxConfig.getCskaoyanmall_wx_index_hot());
        System system5 = new System();
        system5.setKeyValue(wxConfig.getCskaoyanmall_wx_catlog_goods());
        System system6 = new System();
        system6.setKeyValue(wxConfig.getCskaoyanmall_wx_catlog_list());
        System system7 = new System();
        system7.setKeyValue(wxConfig.getCskaoyanmall_wx_index_new());
        systemMapper.updateByExampleSelective(system1, systemExample1);
        systemMapper.updateByExampleSelective(system2, systemExample2);
        systemMapper.updateByExampleSelective(system3, systemExample3);
        systemMapper.updateByExampleSelective(system4, systemExample4);
        systemMapper.updateByExampleSelective(system5, systemExample5);
        systemMapper.updateByExampleSelective(system6, systemExample6);
        systemMapper.updateByExampleSelective(system7, systemExample7);
    }
}

